We have already seen a block of C code. It is the body of the main function. Blocks have the following characteristics:

  1. They start with a { character

  2. They end with a } character

  3. You are allowed to declare local variables at the start of a block.

You will get used to putting statements into blocks as you write programs. You can put as many statements in a block as you like but you must remember to make the start and end { characters are matched up. When I start a new block I indent the lines in the new block by a few spaces. This way I can tell by the layout of the program which bits of code are inside which. On the right you can see an example of blocks in action.

It is fairly obvious that the first block of statements are hanging under the if, and the second set are dependent on the else. The C compiler doesn't care how you lay the code out, as long as it is legal. Many learned people have written huge books which consider the precise position of the { and } characters (which are often referred to as braces). I don't care what the books say, and I advise you to use a layout regime which works for you. If you are happy with mine, then just copy it.